Now let's get Ralph to walk around a little bit.
Ralph is our NPC.
I'm going to use the simplest method.
I'm going to put some waypoints down, right?
So I'm just going to put a part and then I'm going to say WP for Waypoint if I can get that.
There you go.
WP And I'll make it smaller, maybe make the size one by one by one and we're going to anchor it.
There's anchored, click anchored, go up a little bit, can collide off and let's make it invisible.
Well, let's make it.
We're going to make it invisible, but let's make it partially invisible so we can still kind of see
it while we're working on it.
We'll make it all the way invisible when we're done.
So we've got a little part right there.
Let's add a couple of them.
Let's do a control D to duplicate that control de.
Control day air.
We got a few waypoints.
We've got a little square going.
Let's grab all those waypoints.
Click then chef click.
Right click group as folder.
Let's do folder.
It works for model two.
It's your choice.
I'm going to call these w p.
S waypoints with the capital.
W I think I'm going to move them inside.
Ralph.
I'm just going to keep my waypoints inside my MPC.
Now on Ralph, let's add a script to make them walk around, make them walk to those waypoints and it's
called a script move.
And P.S., let's get rid of our print statement on our Move MPC script.
There we go.
And let's get a variable for the character for Ralph, right?
So we have our script script parent There's the script, Ralph's the parent, and that's also the character.
Let's get a variable for our waypoints.
I'll make the variable a lowercase w.
P Yes, we'll get char ralph dot waypoints and then I'll do a get children to get individual waypoints.
And this is going to be a table storing those waypoints.
Now, I need the humanoid of Ralph, so I'll just call that him.
We have our char.
We could do a wait for child, but Ralph is just sitting there.
We're not doing any responding or anything.
If we start doing that, we will do a wait for child.
I'm just going to do dot humanoid, right?
It's easier.
Oh, one more variable.
We need an index.
Set it to one.
The index is going to determine in our waypoints which waypoint we're moving to.
So this will be one, two, three, four.
So let's get let's get the humanoid and then we'll get this oh colon move to we'll get our W piece,
access the WP tables with those square brackets using the ID X variable and then we'll have possession.
Right.
So this W piece is storing all four of our points.
Index starts out at one, so it's going to say Oh WP that's a variable for that.
Oh, there we go.
But I really need to go to the position.
Dot position.
Cool.
Let's go ahead and wait a little bit to get in the game to see Ralph actually move.
So I'll wait 5 seconds, then I'll move to my first point.
And where is he?
There he goes.
He ran up to the point.
All right.
That's pretty cool.
Let's get him to go to the points over and over and over again like a patrol.
Now, move to has this fires off this cool event called Move to Finish when the NPC actually arrives.
There's a timeout there too, so you have to make the move to less than 6 seconds.
I believe it is now.
Or you'll get the timeout and I'll just stop you.
I'll have to do something new, but we're not going to make our waypoints that far away.
We won't run into that trouble.
But if I do a humanoid or HUME dot move to finish, this is going to fire.
When we arrive to our location, I will connect that to an anonymous function.
And then that function I'm going to get my index and then I'll increase it.
I'll do a plus equals one.
But if I get more than four, I've got to go back to one.
Right?
I don't want to go too high.
So if I say if index is greater than the number of points in WPX or the number of elements in WP'S index
will now equal one again.
So we're just going to keep increasing it until we get too high.
Then we'll start over at one.
Then I'll just get my HUME move to WPX, whatever that next index is.
So it might be like two wickets.
The four is going to go back to one and I'll say possession needs to go to the possession.
So now we have our patrol working.
It doesn't do anything.
He doesn't stop or anything.
He just keeps running.
Let's see.
There he goes.
And let's go ahead and bring our bring up our output window, make sure we don't have any errors.
I think he's going pretty good.
It's kind of fast for a patrol, though, if he's not moving at all.
Check down here and also check his humanoid root part to make sure it's not anchored.
That's the most common error.
Let's slow them down.
So he's more.
More like a stroll, right?
More of a patrol speed right under the humanoid.
We can do that anywhere under where we decline, where we declare.
HUME We could do this.
HUME Dot walk speed, and then let's make it like eight as normally 16.
Let's try it.
Here we go.
Yeah, that's more of a patrol.
Looks like he's ready for business.
All right.
Pretty cool.
And we'll add to that in the next video.